
import {deepCopyObjArray} from '../../../assets/js/help';

export default {
  data(){
    return{
      dialogVisibleForDetail: false, //查看详情框
      bigImgPath: ''
    }
  },
  filters:{
    carNoDis: function(value) {
      if(value && value.length>0){
        if(value.length==4){
          return '自助码'+value
        }
        if(value.indexOf("未识别")<=-1 && !/^[\u4E00-\u9FA5]{1,1}/.test(value)){
          return ''+value
        }
        return value;
      }
    },
    cityReliefValue: function(value){
      return !value ? 0 : value
    },
    parkReliefValue: function(value){
      return !value ? 0 : value
    }
  },
  created() {
    this.fetchInPassMode()
    this.fetchOutPassMode()
  },
  methods:{
    // 获取搜索项-进场放行模式-下拉项
    fetchInPassMode(){
      let self = this
      API.fetchGet('/park/carLeaveHistory/getPresentCarCheckInTypeList.do',{}).then(res=>{
        if(res && res.data){
          self.searchList[3].options = []
          let options = []
          options.push({name: "全部", value: ""})
          res.data.forEach(elem=>{
            let obj = {
              name: elem.name,
              value: elem.value
            }
            options.push(obj)
          })
          self.searchList[3].options = deepCopyObjArray(options)
        }
      },err=>{})
    },
    // 获取搜索项-离场放行模式-下拉项
    fetchOutPassMode(){
      let self = this
      API.fetchGet('/park/carLeaveHistory/getPresentCarCheckOutTypeList.do',{}).then(res=>{
        if(res && res.data){
          self.searchList[5].options = []
          let options = []
          options.push({name: "全部", value: ""})
          res.data.forEach(elem=>{
            let obj = {
              name: elem.name,
              value: elem.value
            }
            options.push(obj)
          })
          self.searchList[5].options = deepCopyObjArray(options)
        }
      },err=>{})
    },
    // 获取离场通道列表
    getLeaveChannelList(){
      let self = this
      API.fetchGet('commonFun/channel/findLeaveChannelList.do',{}).then(res=>{
        let data = res.data ? res.data : {}
        let leaveChannelList = []
        leaveChannelList.push({name: "全部", value: ""})
        for(var key in data){
            let obj = data[key]
            obj.forEach(element => {
                let tmpObj = {
                    value: element.entranceName,
                    name: element.entranceName
                } 
                leaveChannelList.push(tmpObj)
            });
        }
        self.searchList[8].value = ""
        self.searchList[8].options = leaveChannelList
      },err=>{})
    },
    // 查看已绑定的车牌号
    checkBindingCarCode(row,modalName){
      let self = this
      self.bindingCarCodeList = []
      let params = {
          logicCardCode: row.carNo
      }
      API.fetchGet('monthTicketBill/getLogicCardCodeDetail',params).then(res=>{
          if(res.data){
              let data = res.data
              let obj = {
                carCode: data.logicCardCode, //车牌
              }
              if(data.openid){ //微信
                obj.cardCode = data.nickname //备注卡号
              }else{
                obj.cardCode = data.cardCode //备注卡号
              }
              self.bindingCarCodeList.push(obj)
          }
          self.toOpenModal(modalName)
      },err=>{})
    },
    getList(){
      let self = this
      let params = $.extend({}, this.searchParams, this.otherParams);
      if(!params.parkIds){
        this.showToast('请先选择停车场!',0)
        return
      }
      if(params.hasOwnProperty("query_carNo")){
        delete params.query_carNo
        let attribStr = this.searchList[1].value
        params[attribStr] = this.searchList[1].inputVal
      }
      if(params){
        for(let key in params){
          if(params[key]==="" || params[key]===null){
            delete params[key]
          }
        }
      }
      if(params['areaIds']){ //选了区域
          self.theadsInfo[1].initHidden = false
      }else{
          self.theadsInfo[1].initHidden = true
      }
      self.isResetTable = !self.isResetTable
      this.getParkInoutRecordList(params)
    },
    showBigImgModal(name, path) {
      this.bigImgPath = path;
      this.toOpenImgModal(name, path);
    },
    getParkInoutRecordList(aparams){
      let self = this,
        params = {
          page: this.pageNumber,
          rp: this.pageSize
        };
      params = $.extend({},params,aparams)
      API.fetchGet('park/carLeaveHistory/pageListParkingRecord.do',params).then(res=>{
        let data = res.data
        self.tbodysInfo = []
        self.total = data.total
        self.tbodysInfo = data.rows
      },err=>{})
    },
    toDetail(row){
      let self = this,
      params = {
        topBillCode: row.topBillCode
      };
      API.fetchGet('park/carLeaveHistory/toInOutRecordDetail.do',params).then(res=>{
        let data = res.data
        self.tableData.parkName = data.parkName
        self.tableData.carNo = row.carNo
        self.tableData.checkInTimeStr = data.checkInTimeStr
        self.tableData.checkOutTimeStr = data.checkOutTimeStr;
        self.tableData.parkTime = data.parkTime;
        self.tableData.billValue=data.billValue;
        self.tableData.needPay=data.needPay;
        self.tableData.remark = data.remark;
        self.tableData.chargeTimeStr = data.chargeTimeStr
        self.detailData = []
        for(let i = 0; i<data.billDetails.length; i++){
          self.detailData.push(data.billDetails[i])
        }
        self.dialogVisibleForDetail = true
      },err=>{})
    },
    exportData() {
      let self = this;
      let theadsArr = []
      for (let i = 0; i < self.theadsInfo.length; i++) {
        if (self.theadsInfo[i].checked) {
          theadsArr.push(self.theadsInfo[i].prop)
        }
      }
      let params = {
        meterList: theadsArr.join(',')
      };

      params = $.extend({}, params, this.searchParams, this.otherParams);
      if(params.hasOwnProperty("query_carNo")){
        delete params.query_carNo
        let attribStr = this.searchList[1].value
        params[attribStr] = this.searchList[1].inputVal
      }
      for(let key in params){
        if(params.hasOwnProperty(key)){
            if(params[key]!==0 && !params[key]){
              delete params[key]
            }
        }
      }
      self.showDialog("确认导出该报表?", '', function () {
        self.toExportAsync('park/carLeaveHistory/exportParkingRecord.do', params);
      });
    }
  }
}